/**
 * Created by minigci.he on 16/9/21.
 */
console.log('-----------------------------')
console.log('test21')

let _counter = new WeakMap();
let _action = new WeakMap();

class Countdown{
    constructor(counter, action){
        _counter.set(this, counter);
        _action.set(this, action)
    }
    dec(){
        let counter = _counter.get(this);
        if(counter < 1) return;
        counter --;
        _counter.set(this, counter);
        if(counter === 0){
            _action.get(this)();
        }
    }
}

let c = new Countdown(2, () => console.log('DONE'))
c.dec()
c.dec()